//此为测试地址,并非真实地址
export const baseUrl = 'https://ssl.jumikeji.com';
// 定义基础请求路径(后端服务器地址)
export const request = (opts, data) => {
	let baseDefaultOpts = {
		url: baseUrl + opts.url,
		// 请求接口地址
		data: data,
		// 传入请求参数
		method: opts.method,
		// 配置请求类型
		header: opts.method == 'get' ? {
			'X-Requested-With': 'XMLHttpRequest',
			"Accept": "application/json",
			"Content-Type": "application/json; charset=UTF-8"
		} : {
			'X-Requested-With': 'XMLHttpRequest',
			'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
		},
		// 配置请求头
		dataType: 'json',
	}
	let promise = new Promise(function(resolve, reject) {
		uni.request(baseDefaultOpts).then(
			(res) => {
				if (!res[1].data.success) {
					uni.showToast({
						title: res[1].data.message,
						icon: 'none',
						duration: 2000
					});
					return false;
				} else {
					resolve(res[1].data)
				}
				
			}
		).catch(
			(response) => {
				uni.showToast({
					title: "网络错误",
					icon: 'none',
					duration: 2000
				});
				reject(response)
			}
		)
	})
	return promise
};
